package com.ltz.dao.well;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ltz.dao.base.BaseDao;
import com.ltz.model.MonthlyProductData;
import com.ltz.model.Page;
import com.ltz.model.WellBasicData;

@Repository
public class WellDao extends BaseDao{
	public Page loadList(Page page){
		return this.findByPage(WellBasicData.class, page);
	}
	public Page loadList(Page page,String sql,Object[] values){
		return this.findByPage(page, sql, values, WellBasicData.class);
	}
	public List getWellList(){
		String sql="select id,name from well_basic_data";
		return this.nativeQueryForList(sql, WellBasicData.class);
	}
	public List<Map<String,Object>> queryForList(String sql,Object... args){
		return this.jdbcTemplate.queryForList(sql, args);
	}
	public List findProductionRecord(Date date,int wellGroupId){
		String sql="select d.id id," +
				"d.date_input dateInput," +
				"d.owner owner," +
				"d.well_team_id wellTeamId," +
				"d.well_team_name wellTeamName," +
				"d.date date," +
				"d.water_in waterIn," +
				"d.preduction preduction," +
				"d.oil_in oilIn," +
				"d.na2so4_per_l na2so4PerL," +
				"d.nacl_per_l naclPerL," +
				"d.nacl_water_per_l naclWaterPerL," +
				"d.na2so4_total na2so4Total," +
				"d.nacl_total naclTotal," +
				"d.nacl_total_no_water naclTotalNoWater," +
				"d.pipe_pressure_in pipePressureIn," +
				"d.pressure_back pressureBack," +
				"d.water_temperature waterTemperature," +
				"d.na2so4_temperature na2so4Temperature," +
				"d.operator operator," +
				"d.auditer auditer," +
				"d.remark remark," +
				"d.produce_method produceMethod,t.well_group_name as wellGroupName from monthly_product_data d left join mn_well_group t on d.well_team_id=t.well_group_id where TO_DAYS(d.date) BETWEEN TO_DAYS(?) and TO_DAYS(?) and d.well_team_id=? order by d.date asc";
		Date begin=new Date(date.getYear(),date.getMonth(),1);
		Calendar cd=Calendar.getInstance();
		cd.setTime(date);
		Date end=new Date(date.getYear(),date.getMonth(),cd.getActualMaximum(Calendar.DAY_OF_MONTH));
		List list=this.nativeQueryForList(sql,new Object[]{begin,end,wellGroupId}, MonthlyProductData.class);
		return list;
	}
}
